package com.aidex.biz.controller;

import java.util.List;

import com.aidex.biz.domain.Customer;
import com.aidex.biz.domain.JinjianFiles;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.ProductFiles;
import com.aidex.biz.service.ProductFilesService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 产品资料Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/biz/bizProductFiles")
public class ProductFilesController extends BaseController {
    @Autowired
    private ProductFilesService productFilesService;

    /**
     * 查询产品资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:list')")
    @GetMapping("/list")
    public R<PageInfo> list(ProductFiles productFiles, HttpServletRequest request, HttpServletResponse response) {
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            productFiles.setCompanyId(null);
        } else {
            productFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        productFiles.setPage(new PageDomain(request, response));
        return R.data(productFilesService.findPage(productFiles));
    }

    /**
     * 获取产品资料详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:query')")
    @GetMapping(value = "/{id}")
    public R<ProductFiles> detail(@PathVariable("id") String id) {
        return R.data(productFilesService.get(id));
    }

    /**
     * 新增产品资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:add')")
    @Log(title = "产品资料", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated ProductFiles productFiles) {
        return R.status(productFilesService.save(productFiles));
    }

    /**
     * 修改产品资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:edit')")
    @Log(title = "产品资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated ProductFiles productFiles) {
        return R.status(productFilesService.save(productFiles));
    }


    /**
     * 删除产品资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:remove')")
    @Log(title = "产品资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(productFilesService.deleteProductFilesByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(productFilesService.findMaxSort(new ProductFiles()));
    }

    /**
     * 导出产品资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizProductFiles:export')")
    @Log(title = "产品资料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(ProductFiles productFiles) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            productFiles.setCompanyId(null);
        } else {
            productFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<ProductFiles> list = productFilesService.findList(productFiles);
        ExcelUtil<ProductFiles> util = new ExcelUtil<ProductFiles>(ProductFiles.class);
        return util.exportExcel(list, "产品资料数据");
    }

    /**
     * 根据产品id查询产品所需资料
     *
     * @param jinjianFiles
     * @return
     */
    @Log(title = "根据产品id查询产品所需资料", businessType = BusinessType.SELECT)
    @GetMapping(value = "/findListByProductId")
    public R findListByProductId(JinjianFiles jinjianFiles) {
        List<ProductFiles> list = productFilesService.findListByProductId(jinjianFiles);
        return R.data(list);
    }
}
